;(function(){
var role = require("./role");
var BusCon = require("../../core/bus/_con");
var UserCon = require("../../core/user/_con");
var GoodsCon = require("../../core/goods/_con");
var AchCon = require("../../core/ach/_con");
var db = require("../../core/db/index");
var config = require("../../core/_include/config");
var ResponObj = require("../_include/responObj");	
module.exports = {
	prefix:"/bus/recommend_config",
	get:{
		"/buyId/:bus_id":function () {
			var bus_id = this.params.bus_id;
			var bus = BusCon.get(bus_id);
			if (!bus) {
				throwCusError("找不到指定商家")
			}
			var result = bus.getRecommendConfig();
			this.body = ResponObj("json",result);
		},
		"/":function () {
			var bus = role.getBus(this);
			var result = bus.getRecommendConfig();
			this.body = ResponObj("json",result);
		},
		"/discount":function () {
			var bus = role.getBus(this);
			this.body = ResponObj("json",bus.getRecommendDiscount());
		}
	},
	put:{
		"/":function () {
			var bus = role.getBus(this);
			// console.log(typeof this.request,typeof this.request.body);
			var recommend_config = this.request.body.recommend_config;
			bus.updateRecommendConfig(recommend_config);
			this.body = ResponObj("json",bus.getRecommendConfig());
		},
		"/discount":function () {
			var bus = role.getBus(this);
			var body  = this.request.body;
			if (!body.hasOwnProperty("discount_value")) {
				throwCusError("参数错误")
			}
			var discount_value = body.discount_value;
			bus.updateRecommendDiscount(discount_value);
			this.body = ResponObj("json",bus.getRecommendDiscount());
		}
	},
	"delete":{
		"/discount":function () {
			var bus = role.getBus(this);
			bus.disableRecommendDiscount();
			this.body = ResponObj("json",bus.getRecommendDiscount());
		}
	}
}
}());